package com.dy.course.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.dy.course.common.BaseController;
import com.dy.course.common.ResponseMessage;
import com.dy.course.entity.RoomBean;
import com.dy.course.enumerate.RoomType;
import com.dy.course.model.Room;
import com.dy.course.service.IRoomService;
import com.github.pagehelper.PageInfo;
@Controller
public class RoomController extends BaseController{


	@Autowired
	private IRoomService roomService;
	
	/**
	 * 
	 * 查询教室
	 * 
	 * @param room 查询教室信息
	 * @return 课程列表
	 */
	@RequestMapping(value="/classroom/select")
	@ResponseBody
	public ResponseMessage<PageInfo<Room>> queryCourse(RoomBean room){
		logger.info("【查询课程接口】,参数:room=" + JSON.toJSONString(room));
		room.setType(RoomType.CLASSROOM.getCode().byteValue());
		List<Room> pageList = roomService.query(room);
		PageInfo<Room> page = new PageInfo<Room>(pageList);
		return constructResponse(page);
	}
	
	
	/**
	 * 
	 * 查询会议室
	 * 
	 * @param room
	 *            查询教室信息
	 * @return 课程列表
	 */
	@RequestMapping(value = "/meetingroom/select")
	@ResponseBody
	public ResponseMessage<PageInfo<Room>> queryMeetingroom(RoomBean room) {
		logger.info("【查询会议室接口】,参数:room=" + JSON.toJSONString(room));
		room.setType(RoomType.MEETINGROOM.getCode().byteValue());
		List<Room> pageList = roomService.query(room);
		PageInfo<Room> page = new PageInfo<Room>(pageList);
		return constructResponse(page);
	}
	
	
	/**
	 * 
	 * 创建教室
	 * 
	 * @param room 创建教室
	 * @return 
	 */
	@RequestMapping(value="/room/create", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<Long> createCourse(@RequestBody RoomBean room){
		logger.info("【创建课程/会议接口】,参数:room=" + JSON.toJSONString(room));
//		room.setType(RoomType.CLASSROOM.getCode().byteValue());
		Long id = roomService.insert(room);
		return constructResponse(id);
	}
	
	
	/**
	 * 
	 * 创建会议室
	 * 
	 * @param room
	 *            创建会议室信息
	 * @return  
	 
	@RequestMapping(value = "/meetingroom/create", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<Long> createMeetingroom(@RequestBody RoomBean room) {
		logger.info("【查询会议室接口】,参数:room=" + JSON.toJSONString(room));
		room.setType(RoomType.MEETINGROOM.getCode().byteValue());
		Long id =  roomService.insert(room);
		return constructResponse(id);
	}*/
	/**
	 * 
	 * 删除教室会议室
	 * 
	 * @param room 创建教室
	 * @return 
	 */
	@RequestMapping(value="/room/delete", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<?> deletRoom(@RequestBody RoomBean room){
		logger.info("【删除教室会议室接口】,参数:room=" + JSON.toJSONString(room.getId()));
		roomService.delet(room);
		return constructNullResponse();
	}
	
	/**
	 * 
	 * 删除教室会议室
	 * 
	 * @param room 创建教室
	 * @return 
	 */
	@RequestMapping(value="/room/update", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<?> updateRoom(@RequestBody RoomBean room){
		logger.info("【删除教室会议室接口】,参数:room=" + JSON.toJSONString(room.getId()));
		roomService.update(room);
		return constructNullResponse();
	}
}
